package com.ruoyi.students.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.students.domain.XgStudents;
import com.ruoyi.students.service.IXgStudentsService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生基本信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/students/students")
public class XgStudentsController extends BaseController
{
    @Autowired
    private IXgStudentsService xgStudentsService;

    /**
     * 查询学生基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:students:list')")
    @GetMapping("/list")
    public TableDataInfo list(XgStudents xgStudents)
    {
        startPage();
        List<XgStudents> list = xgStudentsService.selectXgStudentsList(xgStudents);
        return getDataTable(list);
    }

    /**
     * 导出学生基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:students:export')")
    @Log(title = "学生基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XgStudents xgStudents)
    {
        List<XgStudents> list = xgStudentsService.selectXgStudentsList(xgStudents);
        ExcelUtil<XgStudents> util = new ExcelUtil<XgStudents>(XgStudents.class);
        util.exportExcel(response, list, "学生基本信息数据");
    }

    /**
     * 获取学生基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('students:students:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xgStudentsService.selectXgStudentsById(id));
    }

    /**
     * 新增学生基本信息
     */
    @PreAuthorize("@ss.hasPermi('students:students:add')")
    @Log(title = "学生基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XgStudents xgStudents)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        xgStudents.setDeptId(105L);
        xgStudents.setUserId(user.getUserId());
        return toAjax(xgStudentsService.insertXgStudents(xgStudents));
    }

    /**
     * 修改学生基本信息
     */
    @PreAuthorize("@ss.hasPermi('students:students:edit')")
    @Log(title = "学生基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XgStudents xgStudents)
    {
        return toAjax(xgStudentsService.updateXgStudents(xgStudents));
    }

    /**
     * 删除学生基本信息
     */
    @PreAuthorize("@ss.hasPermi('students:students:remove')")
    @Log(title = "学生基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xgStudentsService.deleteXgStudentsByIds(ids));
    }
}
